//
//  commentsTableViewCell.m
//  HaHa
//
//  Created by 元虎的mac on 15/9/22.
//  Copyright (c) 2015年 吉亚平. All rights reserved.
//

#import "commentsTableViewCell.h"

@implementation commentsTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    return self;
}

- (void)addContentView{
    self.commentPhoto = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 30, 30)];
    self.commentPhoto.layer.masksToBounds = YES;
    self.commentPhoto.layer.cornerRadius = _commentPhoto.width/2;
    [self.contentView addSubview:self.commentPhoto];
    
    self.commentName = [[UILabel alloc] initWithFrame:CGRectMake(_commentPhoto.X_width + 5, 15, kScreenWdth-10-_commentPhoto.X_width- 5 - 70, 20)];
    self.commentName.textColor = KgrayColor;
    [self.contentView addSubview:self.commentName];
    
    self.publishedTime = [[UILabel alloc] initWithFrame:CGRectMake(_commentName.X_width+5, 15, 65, 20)];
    self.publishedTime.font = [UIFont boldSystemFontOfSize:11];
    self.publishedTime.textColor = KgrayColor;
    [self.contentView addSubview:self.publishedTime];
    
    self.commentContent = [[UILabel alloc] initWithFrame:CGRectMake(_commentName.X, _commentName.Y_height+10,kScreenWdth-10-_commentPhoto.X_width-5, 20)];
    _commentContent.textAlignment = NSTextAlignmentLeft;
    _commentContent.numberOfLines = 0;
    [self.contentView addSubview:self.commentContent];
}


-(void)setContentWithMode:(commentsMode *)Mode{
    self.commentContent.text = Mode.commentContent;
    self.commentName.text  = Mode.commentName;
    [self.commentPhoto sd_setImageWithURL:[NSURL URLWithString:Mode.commentPhotoUrl] placeholderImage:nil];
    self.publishedTime.text = Mode.publishedTime;
    CGFloat textHeight = [self YYHreturnStringHeight:Mode.commentContent Width:kScreenWdth-65 Font:17];
    self.commentContent.frame = CGRectMake(_commentName.X, _commentName.Y_height+10,kScreenWdth-65, textHeight);
    
}
//计算高度
- (CGFloat)YYHreturnStringHeight:(NSString *)string Width:(CGFloat)Width Font:(int)font{
    CGRect frame = [string boundingRectWithSize:CGSizeMake(Width, 10000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:font] forKey:NSFontAttributeName] context:nil];
    return frame.size.height;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
